<?xml version="1.0" encoding="UTF-8"?>
<html>
    <head>
        <link type="text/css" rel="stylesheet" href="./css/template.css" />
        <link type="text/css" rel="stylesheet" href="./css/SyntaxHighlighter.css" />
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
        <title>JBoss SEAM</title>
        <script language="javascript" src="./js/shInit.js" />
        <script language="javascript" src="./js/shCore.js" />
        <script language="javascript" src="./js/shBrushCpp.js" />
        <script language="javascript" src="./js/shBrushCSharp.js" />
        <script language="javascript" src="./js/shBrushCss.js" />
        <script language="javascript" src="./js/shBrushDelphi.js" />
        <script language="javascript" src="./js/shBrushJava.js" />
        <script language="javascript" src="./js/shBrushJScript.js" />
        <script language="javascript" src="./js/shBrushPhp.js" />
        <script language="javascript" src="./js/shBrushPython.js" />
        <script language="javascript" src="./js/shBrushRuby.js" />
        <script language="javascript" src="./js/shBrushSql.js" />
        <script language="javascript" src="./js/shBrushVb.js" />
        <script language="javascript" src="./js/shBrushXml.js" />
        <keywords>jboss,seam,eclipse,ide,wtp</keywords>
        <keywords />
        <author>Benjamin HUBY</author>
		<style>
			p
			{
				text-align:justify;
			}
		</style>
    </head>
    <body>
        <div class="chapter">
            <h2>Introduction</h2>
            <p>The application framework JBoss Seam integrates jPDL, as its language of business processes, facilitating in this way the writing of applications containing complex workflows, the flow of Web applications pages and user interactions. You will find below a presentation of the capabilities of Jboss Seam, and the analysis of a demo application.</p>
        </div>
        <div class="chapter">
            <h2>Presentation of the need tools</h2>
            <p>A set of tools are needed to facilitate the JEE development(Java EE). Although the new specifications simplifie enormously the things.</p>
            <div class="subChapter">
                <h3>Eclipse</h3>
                <p>It's not necessay to present the &laquo;Eclipse&raquo; IDE. It&rsquo;s one of the most widely used in the Java world without this one is unknown by the other such as php, C, C + +. The structure and architecture of this tool has made all his power (simple configuration, easy development of plugins and quick set-up).</p>
                <p>
                    <center><img src="./images/jb-eclipse.jpg" alt="Eclipse" /></center>
                    <br />
                    You can download Eclipse at the following address:
                    <a href="http://www.eclipse.org/downloads" target="_about">Eclipse</a>
                </p>
                <h3>WTP : Webtool Platform</h3>
                <p>WTP is an Open-Source plugin for Eclipse. The development was launched by IBM and the community 4 years ago. The project is currently at the stabele version 2.0.1 and has become indispensable for the Web developers. You have a short summary of what is proposed by this plugin below:</p>
                <ul>
                    <li>Project templates (Web / EJB / JSP / Client J2EE)</li>
                    <li>XDoclet integration</li>
                    <li>JPA tools</li>
                    <li>Visual Editor for JSP</li>
                    <li>XML Editor</li>
                    <li>HTML, CSS and Javascript editors</li>
                    <li>View and special perspectives for J2EE</li>
                </ul>
                <p>The version 3.0 is about to be prepared and is likely to bring even more functionality.</p>
                <p>You can either download the plugin and its dependencies or download a bundle including the Eclipse environment and the plugin already installed (advice) : <a href="http://www.eclipse.org/webtools" target="_about">Eclipse WTP</a></p>
                <h3>JBoss</h3>
                <p>JBoss is an Open-Source application server J2EE, which since version 3, has been able  integrated into the professional world. Two versions particulary concern  us: JBoss 4: a version of migration from the J2EE specification to JAVA EE 5 and JBoss 5: future version implementing the entire specification JAVA EE 5.The strong point of this server is that it has proposed very quickly an application server including EJB3 specification (including directly from the version 4.0.2). We will use JBoss 4.2.2 (the latest stable version of JBoss).</p>
                <p>
                    JBoss is downloadable on this website : <a href="http://www.jboss.com" target="_about">ici</a>
                </p>
                <h3>JBoss Seam</h3>
                <p>Download JBoss Seam and unpack it in an outside working directory of the server JBoss. Edit and configure the file build.properties in your Seam directory by specifying the JBoss set-up path.</p>
            </div>
        </div>
        <div class="chapter">
            <h2>JBoss Seam</h2>
            <div class="subChapter">
                <h3>Presentation</h3>
                <p>JBoss Seam has the aim to manage the issues for Java Web applications using JSF and EJB 3.0. Indeed, it was cumbersome and risky to make the link between each two. It also helps reduce the layers of artificial code related to the structure of the application and close the EJB layer to the web. It provides to access the EJBs as backing beans for JSF.</p>
                <p>Thus it gives the developer the choice of layers that its application requiresz, since there is no artificial limits. Finally, it manages automatically the components of applications: a developer interacts with components by retrieving and storing them from and in the chosen context.</p>
                <h3>A contextual programming model</h3>
                <p>The notion of context is used in many models of the Java programming. For example user application in connection is maintained in the context Session. JBoss Seam adds three contexts to the many that already exist: Conversation, Process and Application</p>
                <p>The first allows you to define and manage easily the conversations between different applications. The second manages the process to define the tasks and conversations among themselves in a similar manner to JBoss jBPM. The third is a context available during the application.</p>
                <p>All these contexts are managed by JBoss Seam, which is also linked to a default component. Thus, a logged user can be represented by a component User linked to a session. The developer must just only declare the dependencies related to the component before running it.JBoss Seam enables the production of an optimized code and reusable.</p>
                <h3>Portable and light</h3>
                <p>JBoss Seam uses onlt metadata annotation to declare JDK 5.0 and combine components to a context.<br>It doesn&rsquo;t use XML. It supports all JSF implementations. Although it&rsquo;s recommended to use it with EJB 3.0 and also manages persistent Hibernate and POJO classes.</p>
            </div>
        </div>
        <div class="chapter">
            <h2>Analysis of the demo</h2>
            <div class="subChapter">
                <h3>Run the demo</h3>
                <p>In the directory jboss-seam/examples/booking directory, type ant deploy to compile and deploy demo Hotel Booking.</p>
                <p> Launch a browser and try to connect on the address : http://localhost:8080/seam-booking/</p>
                <p>The demonstration is also available on the JBoss Website. Create an account by clicking on Register to enter then on the principaleEntity bean interface.<br>
                    <a href="http://seam.demo.jboss.com/home.seam">le site de JBoss</a>
                </p>
                <h3>Code of the demo</h3>
                <textarea name="code" class="java">
                    @Stateful
					@Name("hotelBooking")
					@Interceptor(SeamInterceptor.class)
					@Conversational(ifNotBegunOutcome = "main")
					@LoggedIn
					public class HotelBookingAction implements HotelBooking, Serializable {
					private static final Logger log = Logger.getLogger(HotelBooking.class);
					@PersistenceContext(type = EXTENDED)
					private EntityManager em;
					private String searchString;
					@DataModel
					private List
                    <hotel>hotels;
						@DataModelSelectionIndex
						private int hotelIndex;
						@Out(required = false)
						private Hotel hotel;
						@In(required = false)
						@Out(required = false)
						@Valid
						private Booking booking;
						@In
						private User user;
						@In
						private transient FacesContext facesContext;
						// Specify that this method starts a long running conversation
						@Begin
						public String find() {
						hotel = null;
						String searchPattern = searchString == null ? "%" : '%' + searchString.toLowerCase().replace('*', '%') + '%';
						hotels = em.createQuery("from Hotel where lower(name) like :search or lower(city) like :search or lower(zip) like :search or lower(address) like :search")
						.setParameter("search", searchPattern)
						.setMaxResults(50)
						.getResultList();
						log.info(hotels.size() + " hotels found");
						return "main";
						}
						public String getSearchString() {
						return searchString;
						}
						public void setSearchString(String searchString) {
						this.searchString = searchString;
						}
						public String selectHotel() {
						if (hotels == null) return "main";
						setHotel();
						return "selected";
						}
						public String nextHotel() {
						if (hotelIndex
						&lt; hotels.size() - 1) {
						++hotelIndex;
						setHotel();
						}
						return null;
						}
						public String lastHotel() {
						if (hotelIndex &gt; 0) {
						--hotelIndex;
						setHotel();
						}
						return null;
						}
						private void setHotel() {
						hotel = hotels.get(hotelIndex);
						log.info(hotelIndex + "=&gt;" + hotel);
						}
						public String bookHotel() {
						if (hotel == null) return "main";
						booking = new Booking(hotel, user);
						booking.setCheckinDate(new Date());
						booking.setCheckoutDate(new Date());
						return "book";
						}
						@IfInvalid(outcome = REDISPLAY)
						public String setBookingDetails() {
						if (booking == null || hotel == null) return "main";
						if (!booking.getCheckinDate().before(booking.getCheckoutDate())) {
						log.info("invalid booking dates");
						FacesMessage facesMessage = new FacesMessage("Check out date must be later than check in date");
						facesContext.addMessage(null, facesMessage);
						return null;
						} else {
						log.info("valid booking");
						return "success";
						}
						}
						@End
						public String confirm() {
						if (booking == null || hotel == null) return "main";
						em.persist(booking);
						log.info("booking confirmed");
						return "confirmed";
						}
						@Destroy
						@Remove
						public void destroy() {
						log.info("destroyed");
						}
						}</hotel>
                </textarea>
                <h3>Jboss Seam interest</h3>
                <p>Jboss seam enables to solve easily the following problems:</p>
                <ul>
                    <li>The customer fails to complete the transaction</li>
                    <li>The browser doesn't accept cookies</li>
                    <li>The client opens another browser and launches another purchase</li>
                    <li>The customer clicks on the back button of its browser</li>
                </ul>
                <p>JBoss Seam by endeavouring to manage the concept of Conversation will enable to lead a transaction and a dialogue with the user very easily.</p>
                <p>
                    In the demo "HotelBookingAction", we find again  a Stateful Session Bean indicated by
                    <b>@Stateful</b>
                    (The tag
                    <b>@Name</b>
                    is a Seam tag giving a name to a SSB) wich will allow, in the part JSF,to trigger actions and assign them to buttons on the Web page.
                    <br />
                    <b>@Interceptor</b>
                    is a Seam tag needed to realise the Bijection.
                    <br />
                    <b>@Conversational</b>
                    enable to assign a context of conversation to a SSB.
                    <br />
                    Finally
                    <b>@LoggedIn</b>
                    is particular to the application HotelBooking, it allows you to restrict execution of this Bean on an authenticated user.
                </p>
                <h3>The communication context</h3>
                <p>Here the role of different encountered  annotations to introduce you  one of the seam principles, the conversation context.</p>
                <p>
                    <textarea name="code" class="java">@Begin
						public String find() {};</textarea>
                    The method find is marked with the annotation
                    <b>@Begin</b>
                    and the confirm method is marked with the annotation
                    <b>@End</b>
                    .
					These 2 markers allow to start and end the transaction. The conversation is continuous since when the user initiates the find action until he confirms his choice.
                </p>
                <p>
                    <textarea name="code" class="java">@End
						public String confirm() {};</textarea>
                    The confirm() method is called once an hotel has been selected and that a Booking object has been created.
                </p>
                <p>
                    <textarea name="code" class="java">@IfInvalid(outcome = REDISPLAY)
						public String setBookingDetails(){};</textarea>
                    The method setBookingDetails is marked with the annotation @IfInvalid (outcome = REDISPLAY), which allows errors in case of calling the current page.
                </p>
                <h3>The bijection</h3>
                <p>To understand the bijection as proposed by Seam, it's necessary to know an engine IoC (Inversion of Control) as Spring.<br>In a few words, the inversion control is a pattern which is used to declare the variables in your code, a method of writing setMyObject (Object newObject), but not to delegate to a motor assignment of this variable. 
The Bijection is both the inversion control but also the reinjection result in the rest of the application.</p>
                <p>
                    <textarea name="code" class="java">@In(required = false)</textarea>
                    The marker 
                    <b>@In</b>
                    of Seam needs an engine to inject the value of booking at the execution.
                </p>
                <p>
                    <textarea name="code" class="java">@Out(required = false)</textarea>
                    The marker 
                    <b>@Out</b>
                    means that the booking object will be outjected to a context variable after the method was called.
                </p>
                <p>
                    <textarea name="code" class="java">@Valid private Booking booking;</textarea>
                    The Booking variable, which is in the context of the user will be automatically replaced by the value of this variable after each call. 
                    <br />
					The marker 
                    <b>@Valid</b>
                    come from Hibernate.  It helps to validate if the attributes of the object are fully informed.
                </p>
            </div>
        </div>
        <div class="chapter">
            <h2>Conclusion</h2>
            <p>JJBoss Seam is an engine based on JSF and EJB3, which aims to facilitate the writing of an application. 
Realy innovative, Seam can write J2EE application of new generations effectively, more quickly.</p>
        </div>
    </body>
</html>

